import React, { useEffect } from 'react';
import {
  Form,
  Modal,
  Grid,
  Input,
  InputNumber,
  TimePicker,
} from '@arco-design/web-react';
import * as Model from '@/services/model';
const { useForm } = Form;
const { Row, Col } = Grid;
interface DetailModalProps {
  oemInfo?: Model.Oem | false;
  onCancel: () => void;
  onOk: (params: Model.Oem) => void;
}

export const DetailModal = (props: DetailModalProps) => {
  const [form] = useForm();

  useEffect(() => {
    if (props.oemInfo !== false) {
      form.setFieldsValue(props.oemInfo);
    }
  }, [props.oemInfo]);

  const submit = async () => {
    const res = await form.validate();
    if (res) {
      props.onOk(res);
    }
  };
  return (
    <Modal
      visible={props.oemInfo !== false}
      title={`${props.oemInfo && props.oemInfo.id ? '修改' : '新增'}车型`}
      mountOnEnter
      unmountOnExit
      onCancel={props.onCancel}
      onOk={submit}
      alignCenter={false}
      okText="提交"
      cancelText="取消"
      style={{ width: 600 }}
    >
      <Form
        form={form}
        labelAlign="right"
        labelCol={{ span: 6 }}
        wrapperCol={{ span: 18 }}
      >
        <Row gutter={24}>
          <Col span={24}>
            <Form.Item label="主机厂编号" field="id" required>
              <Input placeholder="请输入主机厂编号" allowClear />
            </Form.Item>
          </Col>
          <Col span={24}>
            <Form.Item label="主机厂名称" field="name" required>
              <Input placeholder="请输入主机厂名称" allowClear />
            </Form.Item>
          </Col>
          <Col span={24}>
            <Form.Item label="主机厂地址" field="address" required>
              <Input placeholder="请输入主机厂名称" allowClear />
            </Form.Item>
          </Col>
          <Col span={24}>
            <Form.Item label="主机厂工作时间" field="workPeriod" required>
              <TimePicker.RangePicker placeholder={['开始时间', '结束时间']} />
            </Form.Item>
          </Col>
        </Row>
      </Form>
    </Modal>
  );
};
